/*     */ package com.zimbra.cs.account.ldap;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Provisioning.Result;
/*     */ import com.zimbra.cs.fb.ExchangeEWSFreeBusyProvider;
/*     */ import com.zimbra.cs.fb.ExchangeFreeBusyProvider;
/*     */ import com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo;
/*     */ import java.io.IOException;
/*     */ import java.io.PrintStream;
/*     */ import java.net.ConnectException;
/*     */ import java.net.InetAddress;
/*     */ import java.net.UnknownHostException;
/*     */ import java.util.Map;
/*     */ import javax.net.ssl.SSLHandshakeException;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class Check
/*     */ {
/*     */   public static final String STATUS_OK = "check.OK";
/*     */   public static final String STATUS_UNKNOWN_HOST = "check.UNKNOWN_HOST";
/*     */   public static final String STATUS_CONNECTION_REFUSED = "check.CONNECTION_REFUSED";
/*     */   public static final String STATUS_SSL_HANDSHAKE_FAILURE = "check.SSL_HANDSHAKE_FAILURE";
/*     */   public static final String STATUS_COMMUNICATION_FAILURE = "check.COMMUNICATION_FAILURE";
/*     */   public static final String STATUS_AUTH_FAILED = "check.AUTH_FAILED";
/*     */   public static final String STATUS_AUTH_NOT_SUPPORTED = "check.AUTH_NOT_SUPPORTED";
/*     */   public static final String STATUS_NAME_NOT_FOUND = "check.NAME_NOT_FOUND";
/*     */   public static final String STATUS_INVALID_SEARCH_FILTER = "check.INVALID_SEARCH_FILTER";
/*     */   public static final String STATUS_FAILURE = "check.FAILURE";
/*     */   public static final String STATUS_BAD_URL = "check.BAD_URL";
/*     */   public static final String STATUS_FORBIDDEN = "check.FORBIDDEN";
/*     */   
/*     */   public static String getRequiredAttr(Map attrs, String name)
/*     */     throws ServiceException
/*     */   {
/*  70 */     String value = (String)attrs.get(name);
/*  71 */     if (value == null)
/*  72 */       throw ServiceException.INVALID_REQUEST("must specifiy: " + name, null);
/*  73 */     return value;
/*     */   }
/*     */   
/*     */   public static String[] getRequiredMultiAttr(Map attrs, String name) throws ServiceException {
/*  77 */     Object v = attrs.get(name);
/*  78 */     if ((v instanceof String)) return new String[] { (String)v };
/*  79 */     if ((v instanceof String[])) {
/*  80 */       String[] value = (String[])v;
/*  81 */       if ((value != null) && (value.length > 0))
/*  82 */         return value;
/*     */     }
/*  84 */     throw ServiceException.INVALID_REQUEST("must specifiy: " + name, null);
/*     */   }
/*     */   
/*     */   public static Provisioning.Result checkHostnameResolve(String hostname) {
/*     */     try {
/*  89 */       InetAddress.getByName(hostname);
/*     */     } catch (UnknownHostException e) {
/*  91 */       return new Provisioning.Result("check.UNKNOWN_HOST", e, (String)null);
/*     */     }
/*  93 */     return new Provisioning.Result("check.OK", "", (String)null);
/*     */   }
/*     */   
/*     */   public static Provisioning.Result checkExchangeAuth(ExchangeFreeBusyProvider.ServerInfo sinfo, Account acct) throws ServiceException {
/*     */     try {
/*  98 */       int code = ExchangeFreeBusyProvider.checkAuth(sinfo, acct);
/*  99 */       switch (code) {
/*     */       case 400: 
/*     */       case 404: 
/* 102 */         return new Provisioning.Result("check.BAD_URL", "", null);
/*     */       case 401: 
/*     */       case 403: 
/* 105 */         return new Provisioning.Result("check.AUTH_FAILED", "", null);
/*     */       }
/*     */     } catch (IOException e) {
/* 108 */       return toResult(e, "");
/*     */     }
/* 110 */     return new Provisioning.Result("check.OK", "", null);
/*     */   }
/*     */   
/*     */   public static Provisioning.Result checkExchangeEWSAuth(ExchangeFreeBusyProvider.ServerInfo sinfo, Account acct) {
/*     */     try {
/* 115 */       int code = ExchangeEWSFreeBusyProvider.checkAuth(sinfo, acct);
/* 116 */       switch (code) {
/*     */       case 400: 
/*     */       case 404: 
/* 119 */         return new Provisioning.Result("check.BAD_URL", "", null);
/*     */       case 401: 
/*     */       case 403: 
/* 122 */         return new Provisioning.Result("check.AUTH_FAILED", "", null);
/*     */       }
/*     */     } catch (Exception e) {
/* 125 */       return toResult(e, "");
/*     */     }
/* 127 */     return new Provisioning.Result("check.OK", "", null);
/*     */   }
/*     */   
/*     */   public static Provisioning.Result toResult(Exception e, String dn) {
/* 131 */     if ((e instanceof UnknownHostException))
/* 132 */       return new Provisioning.Result("check.UNKNOWN_HOST", e, dn);
/* 133 */     if ((e instanceof ConnectException))
/* 134 */       return new Provisioning.Result("check.CONNECTION_REFUSED", e, dn);
/* 135 */     if ((e instanceof SSLHandshakeException)) {
/* 136 */       return new Provisioning.Result("check.SSL_HANDSHAKE_FAILURE", e, dn);
/*     */     }
/* 138 */     return new Provisioning.Result("check.COMMUNICATION_FAILURE", e, dn);
/*     */   }
/*     */   
/*     */   private static void testCheckHostnameResolve()
/*     */   {
/* 143 */     Provisioning.Result r = checkHostnameResolve("slapshot");
/* 144 */     System.out.println(r);
/*     */   }
/*     */   
/*     */   public static void main(String[] args) {}
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/Check.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */